package common

import (
	"context"
	"fmt"
	"github.com/qiniu/go-sdk/v7/auth/qbox"
	"github.com/qiniu/go-sdk/v7/storage"
)

type QiNiuConfig struct {
	Link   string
	Ak     string
	Sk     string
	Bucket string
}

var q = QiNiuConfig{
	Link:   BASEURL,
	Ak:     "fcnbgBrBgav_56VE5t2c21pkgItykZVIPgHRhVZ3",
	Sk:     "Rbyq18NE5MWVpBtPKMNv_56KEWYTMvnODAEUEQyr",
	Bucket: "qigeyu",
}
var mac *qbox.Mac = qbox.NewMac(q.Ak, q.Sk)
var cfg = storage.Config{
	Region:        &storage.ZoneHuanan,
	UseHTTPS:      false,
	UseCdnDomains: true,
}

//	var cnt = client.Client{
//		Client: &http.Client{
//			Timeout: time.Second * 10,
//		},
//	}
//
//	var manager = storage.BucketManager{
//		Cfg:    &cfg,
//		Mac:    mac,
//		Client: &cnt,
//	}
var putPolicy = storage.PutPolicy{
	Scope: q.Bucket,
}

func QiniuUploader(basePath string, name string) bool {
	formUploader := storage.NewFormUploader(&cfg)
	ret := storage.PutRet{}
	token := putPolicy.UploadToken(mac)
	err := formUploader.PutFile(context.Background(), &ret, token, name, basePath, &storage.PutExtra{})
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}
